package com.example.edu.Controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class FrontendController {

    @RequestMapping("/{path:^(?!api|assets)[^.]*}/**")
    public String forward(HttpServletRequest request) {
        String uri = request.getRequestURI(); // 获取完整路径
        System.out.println("请求路径: " + uri);

        //避免 /api/ 和 /assets/ 被错误匹配
        if (uri.startsWith("/api/") || uri.startsWith("/assets/")) {
            return "forward:/error"; // 直接返回 404 处理
        }

        return "forward:/index.html"; // 交给前端 Vue 处理
    }
}

